<extend name="./public/frame.html"/>
<block name="content">
	<div class="layer_content">
		<div class="layer_form">
			<div class="down_icon"></div>
			<div class="layer_div">
				<div class="layer_tit">
					手机号：
				</div>
				<div class="layer_control">
					<input type="text" class="w180" id="phone" placeholder="手机号搜索">
				</div>
			</div>

			<div class="layer_div">
				<div class="layer_tit">
					开始时间：
				</div>
				<div class="layer_control">
					<input type="text" class="w180" id="start" placeholder="开始时间（注册）">
				</div>
			</div>
			<div class="layer_div">
				<div class="layer_tit">
					结束时间：
				</div>
				<div class="layer_control">
					<input type="text" class="w180" id="end" placeholder="结束时间（注册）">
				</div>
			</div>
		</div>
		<div class="button_content">
			<button class="layui-btn" data-type="search">搜索</button>
			<button class="layui-btn" id="excel" data-type="excel">导出</button>
		</div>
	</div>
	<table class="layui-table" lay-data="{width:'auto', height:'auto', url:'{:url('User/index')}', page: true, limit: 10, id:'test'}" lay-filter="test">
		<thead>
		<tr>
			<th lay-data="{field:'uid', width:80, fixed: true, align:'center'}">UID</th>
			<th lay-data="{field:'user_phone', width:120, align:'center',}">手机号</th>
			<th lay-data="{field:'register_time', width:160, align:'center'}">注册时间</th>
			<th lay-data="{field:'last_login_time', width:160, align:'center'}">最后登陆时间</th>
			<th lay-data="{field:'refereeTypeName', width:120, align:'center'}">下单总额</th>
			<th lay-data="{field:'inter_order_num', width:120, align:'center'}">下单次数</th>
			<th lay-data="{fixed:'right', toolbar: '#barDemo', width:200, align:'center'}">操作</th>
		</tr>
		</thead>
	</table>

	<div class="layui-hide" id="barDemo">
		{{# if(d.is_close == 0){ }}
		<a lay-event="del">封禁</a>
		{{# }else if(d.is_close == 1){ }}
		<a lay-event="redel" style="color: red;">已封</a>
		{{# } }}
		<a lay-event="detail">详情</a>

	</div>
	<script>
		layui.use(['table','laydate'], function () {
			var table = layui.table,laydate = layui.laydate;
			laydate.render({
				elem: '#start' //指定元素
				, type: 'datetime'
				,theme: '#393D49'
			});
			laydate.render({
				elem: '#end' //指定元素
				,type: 'datetime'
				,theme: '#393D49'
			});
			//监听工具条
			table.on('tool(test)', function (obj) {
				var data = obj.data;
				var layEvent = obj.event;
				var uid = data.uid;
				if (layEvent === 'del') {
					layer.open({
						type: 2,
						title: '设置封号的时间',
						shadeClose: true,
						shade: 0.8,
						area: ['40%', '50%'],
						content: '{:url("/admin/user/user_forbid_time","uid=")}' + uid //iframe的url
					});
				}else if (layEvent === 'redel') {
					layer.confirm('确定解除封禁吗?', function (index) {
						var url = "{:U('ajax_redel')}";
						$.post(url, {'uid': uid}, function (data) {
							switch (data.code) {
								case 1 :
									alert(data.msg);
									break;
								default :
									alert(data.msg);
							}
						}, 'json');
						layer.close(index);
						window.location.reload();
					});

				}else if (layEvent === 'detail') {
					layer.open({
						type: 2,
						title: '用户信息',
						shadeClose: true,
						shade: 0.8,
						area: ['100%', '100%'],
						content: '{:url("/admin/user/detail","uid=")}' + uid //iframe的url
					});
				}else if(layEvent === 'edit'){
					layer.open({
						type: 2,
						title: '添加推荐人',
						shadeClose: true,
						shade: 0.8,
						area: ['40%', '30%'],
						content: '{:url("/admin/user/referEdit","uid=")}' + uid //iframe的url
					});
				}
			});
			var $ = layui.jquery, active = {
				search: function () {
					var phone 		= $("#phone").val();
					var province_id = $("#province_id").val();
					var city_id 	= $("#city_id").val();
					var all_phone 	= $("#all_phone").val();
					var user_status = $("#user_status").val();
					var start 		= $("#start").val();
					var end 		= $("#end").val();
					table.reload('test', {
						url: '/admin/user/index', where: {
							"user_phone": phone,
							"register_province": province_id,
							"register_city": city_id,
							"all_phone":all_phone,
							"user_status":user_status,
							"start_time": start,
							"end_time": end,
						}
					});
				}
				, excel: function () {
					var phone 		= $("#phone").val();
					var province_id = $("#province_id").val();
					var city_id 	= $("#city_id").val();
					var all_phone 	= $("#all_phone").val();
					var user_status = $("#user_status").val();
					var start 		= $("#start").val();
					var end 		= $("#end").val();
					var str = "&user_phone=" + phone + "&register_province="+ province_id + "&register_city=" + city_id + "&all_phone=" + all_phone + "&user_status=" + user_status + "&start_time=" + start + "&end_time=" + end;
					layer.confirm('请选择导出内容', {
						btn: ['全部数据','取消'] //可以无限个按钮
						, btn3: function (index) {
							layer.close(index);
						}
					}, function (index) {
						location = "{:url('excel','headers=')}" + str ;
						layer.close(index);
					});
				}
			};
			$('.layui-btn').on('click', function () {
				var type = $(this).data('type');
				active[type] ? active[type].call(this) : '';
			});
		});
		function getProvinceList(){
			$("#city_id").empty();
			$("#city_id").append('<option value=>请选择城市</option>');
			var province_id = $("#province_id").val();
			$.ajax({
				url:'{:url("/admin/Franchisee/cityList")}',
				async:true,
				type:'post',
				data:{'province_id':province_id},
				success:function(res){
					$("#city_id").append(res);
				},
				error:function(e){
					layer.msg('请求错误');return false;
				}
			})
		};
	</script>
</block>
